<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
    <head>

	<title>Motorbike tour organizing system | Trips</title>
	<style type="text/css">
	.label{
	font-weight:bold;
	}
        </style>

        <style type="text/css">
        <c:import url="styles/decoration.css" />
        </style>

        <link rel="alternate" href="http://localhost:8080/Izsla-war/rss.jsf" type="application/rss+xml" title="Motorbike tours RSS" />
    </head>

    <body>

	<f:view>
	    <f:subview id="header">
		<c:import url="header.jsp"/>
	    </f:subview>

	    <rich:panel header="List of trips">
                <rich:panel header="Search">
		    <h:form>
			<h:panelGrid columns="4">
			    From: <rich:calendar value="#{trips.searchSetting.startTime}"/>
			    To: <rich:calendar value="#{trips.searchSetting.endTime}"/>
			</h:panelGrid>
			<h:panelGrid columns="4">
			    Minimum length: <h:inputText value="#{trips.searchSetting.minLength}">
				<f:validateLongRange minimum="0" maximum="50000"/>
			    </h:inputText>

			    Maximum length: <h:inputText value="#{trips.searchSetting.maxLength}">
				<f:validateLongRange minimum="0" maximum="50000"/>
			    </h:inputText>
			</h:panelGrid>
                        <h:commandButton value="Search" action="#{trips.search}"/>
                    </h:form>
                </rich:panel>


		<h:outputText value="No trip was found for the given serch term!" rendered="#{fn:length(trips.trips) == 0}"/>

		<h:form>
		    <rich:dataGrid value="#{trips.trips}" var="t" columns="1" style="margin:0 auto;" elements="5">
			<rich:panel>
			    <f:facet name="header">
				<h:outputText value="#{t.description}"></h:outputText>
			    </f:facet>


			    <h:panelGrid columns="2">

				    <h:commandLink value="Open" action="#{tripDetails.showTrip}">
					    <f:param name="tripId" value="#{t.id}"/>
				    </h:commandLink>

				    <h:commandLink value="Delete" action="#{trips.onDeleteTrip}" rendered="#{trips.isAdmin}">
					    <f:setPropertyActionListener target="#{trips.deleteId}" value="#{t.id}"/>
				    </h:commandLink>

			    </h:panelGrid>



			    <h:panelGrid columns="2">
				<h:outputText value="Description:" styleClass="label"/>
				<h:outputText value="#{t.description}"/>

				<h:outputText value="Organiser:" styleClass="label"/>
				<h:outputText value="#{t.organiser.name}"/>

				<h:outputText value="Participants:" styleClass="label"/>
				<h:outputFormat value="{0}/{1}">
				    <f:param value="#{t.numParticipants}" />
				    <f:param value="#{t.limit}" />
				</h:outputFormat>

				<h:outputText value="Length:" styleClass="label" />
				<h:outputText value="#{t.distance} km"/>

				<h:outputText value="From:" styleClass="label"/>
				<h:outputText value="#{t.startTime}"/>

				<h:outputText value="To:" styleClass="label"/>
				<h:outputText value="#{t.endTime}"/>

			    </h:panelGrid>

			</rich:panel>

			<f:facet name="footer">
			    <rich:datascroller />
			</f:facet>
		    </rich:dataGrid>
		</h:form>
	    </rich:panel>
	</f:view>
    </body>
</html>

